<template>
  <div class="app-container">
    <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="运输单位名称" prop="gyName">
            <el-input
              v-model="queryParams.gyName"
              placeholder="请输入运输单位名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="法人" prop="gyPerson">
            <el-input
              v-model="queryParams.gyPerson"
              placeholder="请输入法人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="联系电话" prop="gyPhone">
            <el-input
              v-model="queryParams.gyPhone"
              placeholder="请输入联系电话"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="运输单位地址" prop="gyAddr">
            <el-input
              v-model="queryParams.gyAddr"
              placeholder="请输入运输单位地址"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="经度" prop="gyLg">
            <el-input
              v-model="queryParams.gyLg"
              placeholder="请输入经度"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="纬度" prop="gyLt">
            <el-input
              v-model="queryParams.gyLt"
              placeholder="请输入纬度"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="承运车辆型号" prop="gyCycxh">
            <el-input
              v-model="queryParams.gyCycxh"
              placeholder="请输入承运车辆型号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="牌照" prop="gyPz">
            <el-input
              v-model="queryParams.gyPz"
              placeholder="请输入牌照"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="车辆外观照片" prop="gyClwgzp">
            <el-input
              v-model="queryParams.gyClwgzp"
              placeholder="请输入车辆外观照片"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="驾驶人" prop="gyJsr">
            <el-input
              v-model="queryParams.gyJsr"
              placeholder="请输入驾驶人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="驾驶人电话" prop="gyJsrTel">
            <el-input
              v-model="queryParams.gyJsrTel"
              placeholder="请输入驾驶人电话"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="运输日期" prop="gyYsTime">
            <el-date-picker clearable size="small"
              v-model="queryParams.gyYsTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择运输日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="预计到达日期" prop="gyDaodaTime">
            <el-date-picker clearable size="small"
              v-model="queryParams.gyDaodaTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择预计到达日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="运输线路" prop="gyYsLuxian">
            <el-input
              v-model="queryParams.gyYsLuxian"
              placeholder="请输入运输线路"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险废物名称" prop="gyWxfwName">
            <el-input
              v-model="queryParams.gyWxfwName"
              placeholder="请输入危险废物名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险特性" prop="gyWxfwTx">
            <el-input
              v-model="queryParams.gyWxfwTx"
              placeholder="请输入危险特性"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="数量" prop="gyWxfwNum">
            <el-input
              v-model="queryParams.gyWxfwNum"
              placeholder="请输入数量"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="包装方式" prop="gyBz">
            <el-input
              v-model="queryParams.gyBz"
              placeholder="请输入包装方式"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="禁忌" prop="gyJinji">
            <el-input
              v-model="queryParams.gyJinji"
              placeholder="请输入禁忌"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="应急措施" prop="gyYingji">
            <el-input
              v-model="queryParams.gyYingji"
              placeholder="请输入应急措施"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="发运人" prop="gyFayun">
            <el-input
              v-model="queryParams.gyFayun"
              placeholder="请输入发运人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="运达地" prop="gyYunda">
            <el-input
              v-model="queryParams.gyYunda"
              placeholder="请输入运达地"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="危险废物转移联单" prop="gyWuliandan">
            <el-input
              v-model="queryParams.gyWuliandan"
              placeholder="请输入危险废物转移联单"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="冗余" prop="other">
            <el-input
              v-model="queryParams.other"
              placeholder="请输入冗余"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="冗余" prop="otherone">
            <el-input
              v-model="queryParams.otherone"
              placeholder="请输入冗余"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="冗余" prop="othertwo">
            <el-input
              v-model="queryParams.othertwo"
              placeholder="请输入冗余"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="冗余" prop="otherthree">
            <el-input
              v-model="queryParams.otherthree"
              placeholder="请输入冗余"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['solidYunshu:yunshu:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['solidYunshu:yunshu:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['solidYunshu:yunshu:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['solidYunshu:yunshu:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="yunshuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="生产工艺ID" align="center" prop="gyId" />-->
      <el-table-column label="运输单位名称" align="center" prop="gyName"/>
      <!--      <el-table-column label="法人" align="center" prop="gyPerson" />
            <el-table-column label="联系电话" align="center" prop="gyPhone" />
            <el-table-column label="身份信息扫描" align="center" prop="gyCard" />
            <el-table-column label="资格证信息扫描" align="center" prop="gyZigezheng" />
            <el-table-column label="运输单位地址" align="center" prop="gyAddr" />
            <el-table-column label="经度" align="center" prop="gyLg" />
            <el-table-column label="纬度" align="center" prop="gyLt" />-->
      <el-table-column label="承运车辆型号" align="center" prop="gyCycxh"/>
      <el-table-column label="牌照" align="center" prop="gyPz"/>
      <el-table-column label="车辆外观照片" align="center" prop="gyClwgzp"/>
      <el-table-column label="驾驶人" align="center" prop="gyJsr"/>
      <el-table-column label="驾驶人电话" align="center" prop="gyJsrTel"/>
      <el-table-column label="运输日期" align="center" prop="gyYsTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gyYsTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预计到达日期" align="center" prop="gyDaodaTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gyDaodaTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="运输线路" align="center" prop="gyYsLuxian" />-->
      <!--      <el-table-column label="危险废物名称" align="center" prop="gyWxfwName" />
            <el-table-column label="危险特性" align="center" prop="gyWxfwTx" />
            <el-table-column label="数量" align="center" prop="gyWxfwNum" />
            <el-table-column label="包装方式" align="center" prop="gyBz" />
            <el-table-column label="禁忌" align="center" prop="gyJinji" />
            <el-table-column label="应急措施" align="center" prop="gyYingji" />-->
      <el-table-column label="发运人" align="center" prop="gyFayun"/>
      <el-table-column label="运达地" align="center" prop="gyYunda"/>
      <!--      <el-table-column label="危险废物转移联单" align="center" prop="gyWuliandan" />-->
      <!--      <el-table-column label="冗余" align="center" prop="other" />
            <el-table-column label="冗余" align="center" prop="otherone" />
            <el-table-column label="冗余" align="center" prop="othertwo" />
            <el-table-column label="冗余" align="center" prop="otherthree" />
            <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['solidYunshu:yunshu:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['solidYunshu:yunshu:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改固废运输企业对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" class="clearfix " label-width="140px">
        <div class="content-left clearfix">
          <div class="title2"><span> </span>基本信息</div>
          <el-form-item label="运输单位名称" prop="gyName">
            <el-input v-model="form.gyName" placeholder="请输入运输单位名称"/>
          </el-form-item>
          <el-form-item label="法人" prop="gyPerson">
            <el-input v-model="form.gyPerson" placeholder="请输入法人"/>
          </el-form-item>
          <el-form-item label="联系电话" prop="gyPhone">
            <el-input v-model="form.gyPhone" placeholder="请输入联系电话"/>
          </el-form-item>
          <el-form-item label="身份信息扫描" prop="gyCard">
            <ImageUpload v-model="form.gyCard" type="textarea" placeholder="请输入内容"/>
          </el-form-item>
          <el-form-item label="资格证信息扫描" prop="gyZigezheng">
            <ImageUpload v-model="form.gyZigezheng" type="textarea" placeholder="请输入内容"/>
          </el-form-item>
          <el-form-item label="运输单位地址" prop="gyAddr">
            <el-input v-model="form.gyAddr" placeholder="请输入运输单位地址"/>
          </el-form-item>
          <el-form-item label="坐标">
            <el-row>
              <el-col>
                <div class="weidu" style="display:flex;">
                  <div style="width: 40%">
                    <el-input v-model="form.gyLg" placeholder="请输入经度"/>
                  </div>
                  <div style="width: 40%">
                    <el-input v-model="form.gyLt" placeholder="请输入维度"/>
                  </div>
                  <!--                  <div style="width: 20%; text-align: center">坐标</div>-->
                </div>
              </el-col>
            </el-row>
          </el-form-item>
<!--          <el-form-item label="经度" prop="gyLg">
            <el-input v-model="form.gyLg" placeholder="请输入经度"/>
          </el-form-item>
          <el-form-item label="纬度" prop="gyLt">
            <el-input v-model="form.gyLt" placeholder="请输入纬度"/>
          </el-form-item>-->
        </div>
        <div class="content-middle">
          <div class="title2"><span> </span>运输信息</div>
          <el-form-item label="承运车辆型号" prop="gyCycxh">
            <el-input v-model="form.gyCycxh" placeholder="请输入承运车辆型号"/>
          </el-form-item>
          <el-form-item label="牌照" prop="gyPz">
            <el-input v-model="form.gyPz" placeholder="请输入牌照"/>
          </el-form-item>
          <el-form-item label="车辆外观照片" prop="gyClwgzp">
            <el-input v-model="form.gyClwgzp" placeholder="请输入车辆外观照片"/>
          </el-form-item>
          <el-form-item label="驾驶人" prop="gyJsr">
            <el-input v-model="form.gyJsr" placeholder="请输入驾驶人"/>
          </el-form-item>
          <el-form-item label="驾驶人电话" prop="gyJsrTel">
            <el-input v-model="form.gyJsrTel" placeholder="请输入驾驶人电话"/>
          </el-form-item>
          <el-form-item label="运输日期" prop="gyYsTime">
            <el-date-picker clearable size="small"
                            v-model="form.gyYsTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择运输日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="预计到达日期" prop="gyDaodaTime">
            <el-date-picker clearable size="small"
                            v-model="form.gyDaodaTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择预计到达日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="运输线路" prop="gyYsLuxian">
            <el-input v-model="form.gyYsLuxian" placeholder="请输入运输线路"/>
          </el-form-item>
        </div>
        <div class="content-right">
          <div class="title2"><span> </span>危险废物信息</div>
          <el-form-item label="危险废物名称" prop="gyWxfwName">
            <el-input v-model="form.gyWxfwName" placeholder="请输入危险废物名称"/>
          </el-form-item>
          <el-form-item label="危险特性" prop="gyWxfwTx">
            <el-select v-model="form.gyWxfwTx" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_tx"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="数量" prop="gyWxfwNum">
            <el-input v-model="form.gyWxfwNum" type="number" placeholder="请输入数量"/>
          </el-form-item>
          <el-form-item label="包装方式" prop="gyBz">
            <el-input v-model="form.gyBz" placeholder="请输入包装方式"/>
          </el-form-item>
          <el-form-item label="禁忌" prop="gyJinji">
            <el-input v-model="form.gyJinji" placeholder="请输入禁忌"/>
          </el-form-item>
          <el-form-item label="应急措施" prop="gyYingji">
            <el-input v-model="form.gyYingji" placeholder="请输入应急措施"/>
          </el-form-item>
          <el-form-item label="发运人" prop="gyFayun">
            <el-input v-model="form.gyFayun" placeholder="请输入发运人"/>
          </el-form-item>
          <el-form-item label="运达地" prop="gyYunda">
            <el-input v-model="form.gyYunda" placeholder="请输入运达地"/>
          </el-form-item>
          <el-form-item label="危险废物转移联单" prop="gyWuliandan">
            <FileUpload v-model="form.gyWuliandan"/>
          </el-form-item>
        </div>
        <!--        <el-form-item label="冗余" prop="other">
                  <el-input v-model="form.other" placeholder="请输入冗余" />
                </el-form-item>
                <el-form-item label="冗余" prop="otherone">
                  <el-input v-model="form.otherone" placeholder="请输入冗余" />
                </el-form-item>
                <el-form-item label="冗余" prop="othertwo">
                  <el-input v-model="form.othertwo" placeholder="请输入冗余" />
                </el-form-item>
                <el-form-item label="冗余" prop="otherthree">
                  <el-input v-model="form.otherthree" placeholder="请输入冗余" />
                </el-form-item>
                <el-form-item label="删除标志" prop="delFlag">
                  <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addYunshu, delYunshu, exportYunshu, getYunshu, listYunshu, updateYunshu} from "@/api/solidYunshu/yunshu";
import {validatetoTwoPoint,validatePhoneTwo,validateIdNo,validateEMail} from "@/api/validate/validate";


export default {
  name: "Yunshu",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 固废运输企业表格数据
      yunshuList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gyName: null,
        gyPerson: null,
        gyPhone: null,
        gyCard: null,
        gyZigezheng: null,
        gyAddr: null,
        gyLg: null,
        gyLt: null,
        gyCycxh: null,
        gyPz: null,
        gyClwgzp: null,
        gyJsr: null,
        gyJsrTel: null,
        gyYsTime: null,
        gyDaodaTime: null,
        gyYsLuxian: null,
        gyWxfwName: null,
        gyWxfwTx: null,
        gyWxfwNum: null,
        gyBz: null,
        gyJinji: null,
        gyYingji: null,
        gyFayun: null,
        gyYunda: null,
        gyWuliandan: null,
        other: null,
        otherone: null,
        othertwo: null,
        otherthree: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gyName: [
          {required: true, message: "运输单位名称不能为空", trigger: "blur"}
        ],
        gyPhone: [
          {required: true, validator:validatePhoneTwo, trigger: "blur"}
        ],
        gyJsrTel: [
          {required: true,validator:validatePhoneTwo, trigger: "blur"}
        ],
      },
      typeOptions_tx:[]
    };
  },
  created() {
    this.getDicts("wxtx").then(response => {
      this.typeOptions_tx = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询固废运输企业列表 */
    getList() {
      this.loading = true;
      listYunshu(this.queryParams).then(response => {
        this.yunshuList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        gyId: null,
        gyName: null,
        gyPerson: null,
        gyPhone: null,
        gyCard: null,
        gyZigezheng: null,
        gyAddr: null,
        gyLg: null,
        gyLt: null,
        gyCycxh: null,
        gyPz: null,
        gyClwgzp: null,
        gyJsr: null,
        gyJsrTel: null,
        gyYsTime: null,
        gyDaodaTime: null,
        gyYsLuxian: null,
        gyWxfwName: null,
        gyWxfwTx: null,
        gyWxfwNum: null,
        gyBz: null,
        gyJinji: null,
        gyYingji: null,
        gyFayun: null,
        gyYunda: null,
        gyWuliandan: null,
        other: null,
        otherone: null,
        othertwo: null,
        otherthree: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.gyId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加固废运输企业";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const gyId = row.gyId || this.ids
      getYunshu(gyId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改固废运输企业";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.gyId != null) {
            updateYunshu(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYunshu(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const gyIds = row.gyId || this.ids;
      this.$confirm('是否确认删除固废运输企业编号为"' + gyIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delYunshu(gyIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有固废运输企业数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportYunshu(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
